<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ice="http://www.icesoft.com/icefaces/component"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:composite="http://java.sun.com/jsf/composite"
      xmlns:ace="http://www.icefaces.org/icefaces/components">

    <composite:interface>
        <composite:attribute name="question" required="true" />
        <composite:attribute name="typeQuestion" required="true"/>
        <composite:attribute name="listTypeReponse" required="true" />        
        <composite:attribute name="typeReponse" required="true" type="entite.TypeReponseEnum"/>
        <composite:attribute name="rendered" required="true"/>
        <composite:attribute name="ajouterReponse" required="true" method-signature="java.lang.String ajouterReponse()"/>
        <composite:attribute name="target" type="entite.Reponse"/>
        <composite:attribute name="supprimerReponse" required="true" method-signature="java.lang.String supprimerReponse()"/>
        <composite:attribute name="enregistrerQuestionReponse" required="true" method-signature="java.lang.String enregistrerQuestionReponse()"/>        
        <composite:attribute name="fileEntryResults"  type="org.icefaces.component.fileentry.FileEntryResults" />
        <composite:attribute name="sauvegarderImage" required="true" method-signature="java.lang.String sauvegarderImage()"/>

    </composite:interface>

    <composite:implementation>       

        <ice:panelGroup style="float:left;margin-top:10px;" >
            <ice:panelGrid columns="1">

                

                <ice:panelGrid columns="3" visible="#{not (questionController.question.typeRendu eq 'LISTBOX' or questionController.question.typeRendu eq 'TEXTAREA')}">
                    <ice:outputLabel value="Type de la réponse :" for="typeReponse" />
                    <ice:selectOneMenu id="typeReponse" value="#{questionController.typeReponse}" partialSubmit="true" >
                        <f:selectItems value="#{questionController.listTypeReponse}"/>
                    </ice:selectOneMenu>
                    <ice:message for="typeReponse"   errorClass="error"/>

                    <ice:outputLabel value="Choisir une image :" for="typeImage" rendered="#{questionController.typeReponse eq 'IMAGE'}"/>
                    <ace:fileEntry  id="typeImage" results="#{questionController.listFichierImage}" label="UPLOAD" rendered="#{questionController.typeReponse eq 'IMAGE'}"/>
                    <ice:message for="typeImage"   errorClass="error"/>
                </ice:panelGrid>

                <ice:panelGroup styleClass="componentBox" >
                    <ice:panelGroup styleClass="exampleBox firstChildTitle">
                        <ice:panelGroup style="float:left;margin-top:10px">
                            <ice:panelPositioned styleClass="positionPanelContainer" constraint="vertical"
                                                 var="reponse" value="#{questionController.question.reponseCollection}" >
                                <ice:panelGroup style="cursor:move;" styleClass="container" >
                                    <ice:panelGroup styleClass="moveLabel" style="border: 4px red;" >
                                        <!--on affiche uniquement le première élément si c'est une réponse de type textarea-->
                                        <ice:panelGrid columns="6" rendered="#{!(!(reponse eq (questionController.question.reponseCollection.toArray()[0])) and (questionController.question.typeRendu eq 'TEXTAREA'))}">


                                            <ice:outputText value="Libelle de la réponse : " rendered="#{questionController.typeReponse == 'PHRASE' or questionController.question.typeRendu eq 'TEXTAREA' or questionController.question.typeRendu eq 'LISTBOX'}"/>
                                            <ice:inputText value="#{reponse.libelle}" rendered="#{questionController.typeReponse == 'PHRASE' or questionController.question.typeRendu eq 'TEXTAREA' or questionController.question.typeRendu eq 'LISTBOX'}"/>
                                            <ice:inputHidden rendered="#{questionController.typeReponse == 'PHRASE' or questionController.question.typeRendu eq 'TEXTAREA' or questionController.question.typeRendu eq 'LISTBOX'}"/>
                                            <!--value="./../images/icone_valider.png"-->
                                            <ice:outputText value="Image de la réponse : " rendered="#{questionController.typeReponse == 'IMAGE' and not(questionController.question.typeRendu eq 'TEXTAREA' or questionController.question.typeRendu eq 'LISTBOX')}"/>
                                            <!--/resources/images/icone_valider.png-->
                                            <ice:graphicImage value="#{reponse.cheminImage}" width="50" rendered="#{questionController.typeReponse == 'IMAGE' and not(questionController.question.typeRendu eq 'TEXTAREA' or questionController.question.typeRendu eq 'LISTBOX')}"/>
                                            <h:commandButton value="CHARGER IMAGE" action="#{questionController.sauvegarderImage}" rendered="#{questionController.typeReponse == 'IMAGE' and not(questionController.question.typeRendu eq 'TEXTAREA' or questionController.question.typeRendu eq 'LISTBOX')}">
                                                <f:setPropertyActionListener target="#{questionController.reponse}" value="#{reponse}" />
                                            </h:commandButton>

                                            <ice:outputLabel value="Solution : " for="check" rendered="#{!(questionController.question.typeRendu eq 'TEXTAREA')}"/>
                                            <ice:selectBooleanCheckbox value="#{reponse.solution}" id="check"  rendered="#{!(questionController.question.typeRendu eq 'TEXTAREA')}"/>

                                            <ice:commandButton image="/resources/images/icone_supprimer.png" alt="Supprimer une réponse"
                                                               action="#{questionController.supprimerReponse}" value="Supp" visible="#{!(questionController.question.typeRendu eq 'TEXTAREA')}">
                                                <f:setPropertyActionListener target="#{questionController.reponse}" value="#{reponse}" />
                                            </ice:commandButton>


                                        </ice:panelGrid>
                                    </ice:panelGroup>
                                </ice:panelGroup>
                            </ice:panelPositioned>
                        </ice:panelGroup>
                    </ice:panelGroup>
                </ice:panelGroup>

               <ice:panelGrid columns="3" visible="#{questionController.question.typeRendu eq 'RADIO_BUTTON' or questionController.question.typeRendu eq 'CHECKBOX' or questionController.question.typeRendu eq 'LISTBOX'}">
                    <ice:outputLabel value="Ajouter une réponse :" for="ajoutReponse" />
                    <ice:commandButton id="ajoutReponse" image="/resources/images/icone_ajouter.png" alt="Ajouter une réponse"
                                       action="#{questionController.ajouterReponse}" value="Ajout"/>
                    <ice:message for="ajoutReponse"   errorClass="error"/>
                </ice:panelGrid>
                <br/>

                <!--<ice:commandButton  action="#{questionController.enregistrerQuestionReponse}" value="VALIDER"/>-->
                <ice:commandButton action="#{questionController.enregistrerQuestionReponse}" value="VALIDER">
                    <f:setPropertyActionListener target="#{questionnaireController.page}" value="questionnaire" />
                </ice:commandButton>

            </ice:panelGrid>
        </ice:panelGroup>




        <!--
                <ice:panelGroup style="float:left;margin-top:10px;" >
                    <ice:panelGrid columns="1">

                        <ice:panelGrid columns="3" visible="#{cc.attrs.typeQuestion eq 'RADIO_BUTTON' or cc.attrs.typeQuestion eq 'CHECKBOX' or cc.attrs.typeQuestion eq 'LISTBOX'}">
                            <ice:outputLabel value="Ajouter une réponse :" for="ajoutReponse" />
                            <ice:commandButton id="ajoutReponse" image="/resources/images/icone_ajouter.png" alt="Ajouter une réponse"
                                               action="#{cc.attrs.ajouterReponse}" value="Ajout"/>
                            <ice:message for="ajoutReponse"   errorClass="error"/>
                        </ice:panelGrid>

                        <ice:panelGrid columns="3" visible="#{not (cc.attrs.typeQuestion eq 'LISTBOX' or cc.attrs.typeQuestion eq 'TEXTAREA')}">
                            <ice:outputLabel value="Type de la réponse :" for="typeReponse" />
                            <ice:selectOneMenu id="typeReponse" value="#{cc.attrs.typeReponse}" partialSubmit="true" >
                                <f:selectItems value="#{cc.attrs.listTypeReponse}"/>
                            </ice:selectOneMenu>
                            <ice:message for="typeReponse"   errorClass="error"/>

                            <ice:outputLabel value="Choisir une image :" for="typeImage" rendered="#{cc.attrs.typeReponse eq 'IMAGE'}"/>
                            <ace:fileEntry  id="typeImage" results="#{cc.attrs.fileEntryResults}" label="UPLOAD" rendered="#{cc.attrs.typeReponse eq 'IMAGE'}"/>
                            <ice:message for="typeImage"   errorClass="error"/>
                        </ice:panelGrid>

                        <br/>

                        <ice:panelGroup styleClass="componentBox" >
                            <ice:panelGroup styleClass="exampleBox firstChildTitle">
                                <ice:panelGroup style="float:left;margin-top:10px">
                                    <ice:panelPositioned styleClass="positionPanelContainer" constraint="vertical"
                                                         var="reponse" value="#{cc.attrs.question.reponseCollection}" >
                                        <ice:panelGroup style="cursor:move;" styleClass="container" >
                                            <ice:panelGroup styleClass="moveLabel" style="border: 4px red;" >
                                                on affiche uniquement le première élément si c'est une réponse de type textarea
                                                <ice:panelGrid columns="6" rendered="#{!(!(reponse eq (cc.attrs.question.reponseCollection.toArray()[0])) and (cc.attrs.typeQuestion eq 'TEXTAREA'))}">


                                                    <ice:outputText value="Libelle de la réponse : " rendered="#{cc.attrs.typeReponse == 'PHRASE' or cc.attrs.typeQuestion eq 'TEXTAREA' or cc.attrs.typeQuestion eq 'LISTBOX'}"/>
                                                    <ice:inputText value="#{reponse.libelle}" rendered="#{cc.attrs.typeReponse == 'PHRASE' or cc.attrs.typeQuestion eq 'TEXTAREA' or cc.attrs.typeQuestion eq 'LISTBOX'}"/>
                                                    <ice:inputHidden rendered="#{cc.attrs.typeReponse == 'PHRASE' or cc.attrs.typeQuestion eq 'TEXTAREA' or cc.attrs.typeQuestion eq 'LISTBOX'}"/>
                                                    <ice:outputText value="Image de la réponse : " rendered="#{cc.attrs.typeReponse == 'IMAGE' and not(cc.attrs.typeQuestion eq 'TEXTAREA' or cc.attrs.typeQuestion eq 'LISTBOX')}"/>
                                                    <ice:graphicImage value="#{reponse.cheminImage}" width="50" rendered="#{cc.attrs.typeReponse == 'IMAGE' and not(cc.attrs.typeQuestion eq 'TEXTAREA' or cc.attrs.typeQuestion eq 'LISTBOX')}"/>
                                                    <h:commandButton value="CHARGER IMAGE" action="#{cc.attrs.sauvegarderImage}" rendered="#{cc.attrs.typeReponse == 'IMAGE' and not(cc.attrs.typeQuestion eq 'TEXTAREA' or cc.attrs.typeQuestion eq 'LISTBOX')}">
                                                        <f:setPropertyActionListener target="#{cc.attrs.target}" value="#{reponse}" />
                                                    </h:commandButton>

                                                    <ice:outputLabel value="Solution : " for="check" rendered="#{!(cc.attrs.typeQuestion eq 'TEXTAREA')}"/>
                                                    <ice:selectBooleanCheckbox value="#{reponse.solution}" id="check"  rendered="#{!(cc.attrs.typeQuestion eq 'TEXTAREA')}"/>

                                                    <ice:commandButton image="/resources/images/icone_supprimer.png" alt="Supprimer une réponse"
                                                                       action="#{cc.attrs.supprimerReponse}" value="Supp" visible="#{!(cc.attrs.typeQuestion eq 'TEXTAREA')}">
                                                        <f:setPropertyActionListener target="#{cc.attrs.target}" value="#{reponse}" />
                                                    </ice:commandButton>


                                                </ice:panelGrid>
                                            </ice:panelGroup>
                                        </ice:panelGroup>
                                    </ice:panelPositioned>
                                </ice:panelGroup>
                            </ice:panelGroup>
                        </ice:panelGroup>

                        <br/>
                        <br/>

                        <ice:commandButton  action="#{cc.attrs.enregistrerQuestionReponse}" value="VALIDER"/>

                    </ice:panelGrid>
                </ice:panelGroup>
        -->

    </composite:implementation>
</html>

